package com.twodfire.merchant.poi;

import java.beans.IntrospectionException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * 对excel进行操作工具类
 *@author xiliang.xiao
 *@date 2015年1月8日 下午1:46:36
 *
 **/
@SuppressWarnings("rawtypes")
public class ExcelHandle {

    private Map<String,HashMap[]> tempFileMap  = new HashMap<String,HashMap[]>();
    private Map<String,Map<String,Cell>> cellMap = new HashMap<String,Map<String,Cell>>();
    private Map<String,FileInputStream> tempStream = new HashMap<String, FileInputStream>();
    private Map<String,Workbook> tempWorkbook = new HashMap<String, Workbook>();
    private Map<String,Workbook> dataWorkbook = new HashMap<String, Workbook>();

    /**
     * 单无格类
     * @author xiliang.xiao
     *
     */
    class Cell{
        private int column;//列
        private int line;//行
        private CellStyle cellStyle;

        public int getColumn() {
            return column;
        }
        public void setColumn(int column) {
            this.column = column;
        }
        public int getLine() {
            return line;
        }
        public void setLine(int line) {
            this.line = line;
        }
        public CellStyle getCellStyle() {
            return cellStyle;
        }
        public void setCellStyle(CellStyle cellStyle) {
            this.cellStyle = cellStyle;
        }
    }

    /**
     * 向Excel中输入相同title的多条数据
     * @param tempFilePath excel模板文件路径
     * @param writeConfig 填充的配置
     * @param sheet 填充的excel sheet,从0开始
     * @throws IOException
     */
    public void writeListData(String tempFilePath,WriteConfig writeConfig,int sheet) throws IOException, InvocationTargetException, IllegalAccessException {
        //获取模板填充格式位置等数据
        HashMap temp = getTemp(tempFilePath,sheet);
        //以模板为写入工作簿
        Workbook temWorkbook = getTempWorkbook(tempFilePath);
        //获取数据填充开始行
        int startCell = Integer.parseInt((String)temp.get("STARTCELL"));
        //数据填充的sheet
        Sheet wsheet = temWorkbook.getSheetAt(sheet);
        //移除模板开始行数据
        wsheet.removeRow(wsheet.getRow(startCell));

        Collection arrayContent = writeConfig.getArrayContent();
        if(arrayContent!=null&&arrayContent.size()>0){
            Collection<String> arrayKeys = writeConfig.getArrayKeys();
            if(arrayKeys.isEmpty()){
                throw new NullPointerException("template array keys is empty");
            }
            for(Object object:arrayContent){
                if(object instanceof Map){
                    Map map = (Map) object;
                    for(String cell:arrayKeys){
                        //获取对应单元格数据
                        Cell c = getCell(cell,temp,temWorkbook,tempFilePath);
                        if(c!=null){
                            //写入数据
                            ExcelUtil.setValue(wsheet, startCell, c.getColumn(), map.get(cell), c.getCellStyle());
                        }
                    }
                }else{
                    for(String cell:arrayKeys){
                        //获取对应单元格数据
                        Cell c = getCell(cell,temp,temWorkbook,tempFilePath);
                        if(c!=null){
                            //写入数据
                            ExcelUtil.setValue(wsheet, startCell, c.getColumn(), writeConfig.getArrayMethodMap().get(cell).invoke(object), c.getCellStyle());
                        }
                    }
                }
                startCell++;
            }
        }
    }

    /**
     * 向Excel中输入相同title的多条数据
     * @param tempFilePath excel模板文件路径
     * @param cellList 需要填充的数据（模板<!%后的字符串）
     * @param dataList 填充的数据
     * @param sheet 填充的excel sheet,从0开始
     * @throws IOException
     */
    public void writeListData(String tempFilePath,List<String> cellList,List<Map<String,Object>> dataList,int sheet) throws IOException{
        //获取模板填充格式位置等数据
        HashMap temp = getTemp(tempFilePath,sheet);
        //以模板为写入工作簿
        Workbook temWorkbook = getTempWorkbook(tempFilePath);
        //获取数据填充开始行
        int startCell = Integer.parseInt((String)temp.get("STARTCELL"));
        //数据填充的sheet
        Sheet wsheet = temWorkbook.getSheetAt(sheet);
        //移除模板开始行数据
        wsheet.removeRow(wsheet.getRow(startCell));
        if(dataList!=null&&dataList.size()>0){
            for(Map<String,Object> map:dataList){
                for(String cell:cellList){
                    //获取对应单元格数据
                    Cell c = getCell(cell,temp,temWorkbook,tempFilePath);
                    if(c!=null){
                        //写入数据
                        ExcelUtil.setValue(wsheet, startCell, c.getColumn(), map.get(cell), c.getCellStyle());
                    }
                }
                startCell++;
            }
        }
    }

    /**
     * 按模板向Excel中相应地方填充数据
     * @param tempFilePath excel模板文件路径
     * @param writeConfig 填充配置
     * @param sheet 填充的excel sheet,从0开始
     * @throws IOException
     */
    public void writeData(String tempFilePath,WriteConfig writeConfig,int sheet) throws IOException, InvocationTargetException, IllegalAccessException {
        Collection<String> keys = writeConfig.getObjectKeys();
        if(keys==null || keys.isEmpty()){
            throw new NullPointerException("template object keys is empty");
        }
        Object content = writeConfig.getContent();
        if(content==null){
            return;
        }
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //以模板为写入工作簿
        Workbook wbModule = getTempWorkbook(tempFilePath);
        //数据填充的sheet
        Sheet wsheet = wbModule.getSheetAt(sheet);
        if(content instanceof Map){
            Map dataMap = (Map) content;
            if(dataMap!=null&&dataMap.size()>0){
                for(String cell:keys){
                    //获取对应单元格数据
                    Cell c = getCell(cell,tem,wbModule,tempFilePath);
                    if(c!=null){
                        ExcelUtil.setValue(wsheet, c.getLine(), c.getColumn(), dataMap.get(cell), c.getCellStyle());
                    }
                }
            }
        }else{
            for(String cell:keys){
                //获取对应单元格数据
                Cell c = getCell(cell,tem,wbModule,tempFilePath);
                if(c!=null){
                    //写入数据
                    ExcelUtil.setValue(wsheet, c.getLine(), c.getColumn(), writeConfig.getObjectMethodMap().get(cell).invoke(content), c.getCellStyle());
                }
            }
        }
    }

    /**
     * 按模板向Excel中相应地方填充数据
     * @param tempFilePath excel模板文件路径
     * @param cellList 需要填充的数据（模板<%后的字符串）
     * @param dataMap 填充的数据
     * @param sheet 填充的excel sheet,从0开始
     * @throws IOException
     */
    public void writeData(String tempFilePath,List<String> cellList,Map<String,Object> dataMap,int sheet) throws IOException{
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //按模板为写入板
        Workbook wbModule = getTempWorkbook(tempFilePath);
        //数据填充的sheet
        Sheet wsheet = wbModule.getSheetAt(sheet);
        if(dataMap!=null&&dataMap.size()>0){
            for(String cell:cellList){
                //获取对应单元格数据
                Cell c = getCell(cell,tem,wbModule,tempFilePath);
                if(c!=null){
                    ExcelUtil.setValue(wsheet, c.getLine(), c.getColumn(), dataMap.get(cell), c.getCellStyle());
                }
            }
        }
    }

    /**
     * Excel文件读值
     * @param tempFilePath
     * @param cell
     * @param sheet
     * @return
     * @throws IOException
     */
    public Object getValue(String tempFilePath,String cell,int sheet,File excelFile) throws IOException{
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //模板工作区
        Workbook temWorkbook = getTempWorkbook(tempFilePath);
        //数据工作区
        Workbook dataWorkbook = getDataWorkbook(tempFilePath, excelFile);
        //获取对应单元格数据
        Cell c = getCell(cell,tem,temWorkbook,tempFilePath);
        if(c!=null){
            //数据sheet
            Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
            return ExcelUtil.getCellValue(dataSheet, c.getLine(), c.getColumn());
        }else {
            return null;
        }
    }

    /**
     * 获取数据最大行
     * @param tempFilePath
     * @param sheet
     * @param excelFile
     * @return
     * @throws IOException
     */
    public int getMaxLine(String tempFilePath,int sheet,File excelFile) throws IOException {
        //将Excel文件转换为工作区间
        Workbook dataWorkbook = getDataWorkbook(tempFilePath,excelFile) ;
        //数据sheet
        Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
        //文件最后一行
        int lastLine = dataSheet.getLastRowNum();
        return lastLine;
    }

    /**
     * 获取数据列表开始行
     * @param tempFilePath
     * @param sheet
     * @return
     * @throws IOException
     */
    public int getListBeginLine(String tempFilePath,int sheet) throws IOException {
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //获取数据填充开始行
        int startCell = Integer.parseInt((String)tem.get("STARTCELL"));
        return startCell;
    }

    /**
     * 读列表值
     * @param tempFilePath
     * @param readConfig
     * @param sheet
     * @param excelFile
     * @return
     * @throws IOException
     */
    public List<Object> getListValue(String tempFilePath,ReadConfig readConfig,int sheet,File excelFile) throws IOException, InstantiationException, IllegalAccessException, InvocationTargetException {
        if(readConfig.getArrayKeys()==null || readConfig.getArrayClazz()==null){
            throw new NullPointerException("array keys and return class type is null");
        }
        List<Object> dataList = new ArrayList<Object>();
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //获取数据填充开始行
        int startCell = Integer.parseInt((String)tem.get("STARTCELL"));
        //将Excel文件转换为工作区间
        Workbook dataWorkbook = getDataWorkbook(tempFilePath,excelFile) ;
        //数据sheet
        Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
        //文件最后一行
        int lastLine = dataSheet.getLastRowNum();

        for(int i=startCell;i<=lastLine;i++){
            dataList.add(getLineValue(i, tempFilePath, readConfig, sheet, excelFile));
        }
        return dataList;
    }
    
    /**
     * 读值一行列表值
     * @param tempFilePath
     * @param sheet
     * @return
     * @throws IOException
     */
    public Object getLineValue(int line,String tempFilePath,ReadConfig readConfig,int sheet,File excelFile) throws IOException, IllegalAccessException, InstantiationException, InvocationTargetException {
        if(readConfig.getArrayKeys()==null || readConfig.getArrayClazz()==null){
            throw new NullPointerException("array keys and return class type is null");
        }
        Object lineObject;
        if(readConfig.getArrayClazz().isAssignableFrom(Map.class)){
            lineObject = new HashMap<>();
        }else{
            lineObject = readConfig.getArrayClazz().newInstance();
        }
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //按模板为写入板
        Workbook temWorkbook = getTempWorkbook(tempFilePath);
        //将Excel文件转换为工作区间
        Workbook dataWorkbook = getDataWorkbook(tempFilePath,excelFile) ;
        //数据sheet
        Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
        for(String key:readConfig.getArrayKeys()){
            //获取对应单元格数据
            Cell c = getCell(key,tem,temWorkbook,tempFilePath);
            if(c!=null){
                if(lineObject instanceof Map){
                    Map lineMap = (Map) lineObject;
                    lineMap.put(key, ExcelUtil.getCellValue(dataSheet, line, c.getColumn()));
                }else{
                    readConfig.getArrayMethodMap().get(key).invoke(lineObject,ExcelUtil.getCellValue(dataSheet, line, c.getColumn()));
                }
            }
        }
        return lineObject;
    }

    /**
     * 读值列表值
     * @param tempFilePath
     * @param sheet
     * @return
     * @throws IOException
     */
    public List<Map<String,Object>> getListValue(String tempFilePath,List<String> cellList,int sheet,File excelFile) throws IOException{
        List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //获取数据填充开始行
        int startCell = Integer.parseInt((String)tem.get("STARTCELL"));
        //将Excel文件转换为工作区间
        Workbook dataWorkbook = getDataWorkbook(tempFilePath,excelFile) ;
        //数据sheet
        Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
        //文件最后一行
        int lastLine = dataSheet.getLastRowNum();

        for(int i=startCell;i<=lastLine;i++){
            dataList.add(getLineValue(i, tempFilePath, cellList, sheet, excelFile));
        }
        return dataList;
    }

    /**
     * 读值列表值
     * @param tempFilePath
     * @param sheet
     * @return
     * @throws IOException
     */
    public List<Object> getRangeLineValue(String tempFilePath,ReadConfig readConfig,int sheet,File excelFile,int beginLine,int endLine) throws IOException, IllegalAccessException, InvocationTargetException, InstantiationException {
        List<Object> dataList = new ArrayList<>();
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //获取数据填充开始行
        int startCell = Integer.parseInt((String)tem.get("STARTCELL"));
        if(beginLine>startCell){
            startCell = beginLine;
        }
        //将Excel文件转换为工作区间
        Workbook dataWorkbook = getDataWorkbook(tempFilePath,excelFile) ;
        //数据sheet
        Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
        //文件最后一行
        int lastLine = dataSheet.getLastRowNum();
        if(endLine<lastLine){
            lastLine = endLine;
        }

        for(int i=startCell;i<=lastLine;i++){
            dataList.add(getLineValue(i, tempFilePath, readConfig, sheet, excelFile));
        }
        return dataList;
    }

    /**
     * 读值列表值
     * @param tempFilePath
     * @param sheet
     * @return
     * @throws IOException
     */
    public List<Map<String,Object>> getRangeLineValue(String tempFilePath,List<String> cellList,int sheet,File excelFile,int beginLine,int endLine) throws IOException{
        List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //获取数据填充开始行
        int startCell = Integer.parseInt((String)tem.get("STARTCELL"));
        if(beginLine>startCell){
            startCell = beginLine;
        }
        //将Excel文件转换为工作区间
        Workbook dataWorkbook = getDataWorkbook(tempFilePath,excelFile) ;
        //数据sheet
        Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
        //文件最后一行
        int lastLine = dataSheet.getLastRowNum();
        if(endLine<lastLine){
            lastLine = endLine;
        }

        for(int i=startCell;i<=lastLine;i++){
            dataList.add(getLineValue(i, tempFilePath, cellList, sheet, excelFile));
        }
        return dataList;
    }

    /**
     * 读值一行列表值
     * @param tempFilePath
     * @param sheet
     * @return
     * @throws IOException
     */
    public Map<String,Object> getLineValue(int line,String tempFilePath,List<String> cellList,int sheet,File excelFile) throws IOException{
        Map<String,Object> lineMap = new HashMap<String, Object>();
        //获取模板填充格式位置等数据
        HashMap tem = getTemp(tempFilePath,sheet);
        //按模板为写入板
        Workbook temWorkbook = getTempWorkbook(tempFilePath);
        //将Excel文件转换为工作区间
        Workbook dataWorkbook = getDataWorkbook(tempFilePath,excelFile) ;
        //数据sheet
        Sheet dataSheet = dataWorkbook.getSheetAt(sheet);
        for(String cell:cellList){
            //获取对应单元格数据
            Cell c = getCell(cell,tem,temWorkbook,tempFilePath);
            if(c!=null){
                lineMap.put(cell, ExcelUtil.getCellValue(dataSheet, line, c.getColumn()));
            }
        }
        return lineMap;
    }



    /**
     * 获得模板输入流
     * @param tempFilePath
     * @return
     * @throws FileNotFoundException
     */
    private FileInputStream getFileInputStream(String tempFilePath) throws FileNotFoundException {
        if(!tempStream.containsKey(tempFilePath)){
            tempStream.put(tempFilePath, new FileInputStream(tempFilePath));
        }

        return tempStream.get(tempFilePath);
    }

    /**
     * 获得输入工作区
     * @param tempFilePath
     * @return
     * @throws IOException
     * @throws FileNotFoundException
     */
    private Workbook getTempWorkbook(String tempFilePath) throws FileNotFoundException, IOException {
        if(!tempWorkbook.containsKey(tempFilePath)){
            if(tempFilePath.endsWith(".xlsx")){
                tempWorkbook.put(tempFilePath, new XSSFWorkbook(getFileInputStream(tempFilePath)));
            }else if(tempFilePath.endsWith(".xls")){
                tempWorkbook.put(tempFilePath, new HSSFWorkbook(getFileInputStream(tempFilePath)));
            }
        }
        return tempWorkbook.get(tempFilePath);
    }

    /**
     * 获取对应单元格样式等数据数据
     * @param cell
     * @param tem
     * @param wbModule
     * @param tempFilePath
     * @return
     */
    private Cell getCell(String cell, HashMap tem, Workbook wbModule, String tempFilePath) {
        if(!cellMap.get(tempFilePath).containsKey(cell)){
            Cell c = new Cell();

            int[] pos = ExcelUtil.getPos(tem, cell);
            if(pos.length==0){
                throw new NullPointerException("template key("+cell+") not exist");
            }
            if(pos.length>1){
                c.setLine(pos[1]);
            }
            c.setColumn(pos[0]);
            c.setCellStyle((ExcelUtil.getStyle(tem, cell, wbModule)));
            cellMap.get(tempFilePath).put(cell, c);
        }
        return cellMap.get(tempFilePath).get(cell);
    }

    /**
     * 获取模板数据
     * @param tempFilePath 模板文件路径
     * @param sheet
     * @return
     * @throws IOException
     */
    private HashMap getTemp(String tempFilePath, int sheet) throws IOException {
        if(!tempFileMap.containsKey(tempFilePath)){
            tempFileMap.put(tempFilePath, ExcelUtil.getTemplateFile(tempFilePath));
            cellMap.put(tempFilePath, new HashMap<String,Cell>());
        }
        return tempFileMap.get(tempFilePath)[sheet];
    }

    /**
     * 资源关闭
     * @param tempFilePath 模板文件路径
     * @param os 输出流
     * @throws IOException
     * @throws FileNotFoundException
     */
    public void writeAndClose(String tempFilePath,OutputStream os) throws FileNotFoundException, IOException{
        if(getTempWorkbook(tempFilePath)!=null){
            getTempWorkbook(tempFilePath).write(os);
            tempWorkbook.remove(tempFilePath);
        }
        if(getFileInputStream(tempFilePath)!=null){
            getFileInputStream(tempFilePath).close();
            tempStream.remove(tempFilePath);
        }
    }

    /**
     * 获得读取数据工作间
     * @param tempFilePath
     * @param excelFile
     * @return
     * @throws IOException
     * @throws FileNotFoundException
     */
    private Workbook getDataWorkbook(String tempFilePath, File excelFile) throws IOException {
        if(!dataWorkbook.containsKey(tempFilePath)){
            if(tempFilePath.endsWith(".xlsx")){
                dataWorkbook.put(tempFilePath, new XSSFWorkbook(new FileInputStream(excelFile)));
            }else if(tempFilePath.endsWith(".xls")){
                dataWorkbook.put(tempFilePath, new HSSFWorkbook(new FileInputStream(excelFile)));
            }
        }
        return dataWorkbook.get(tempFilePath);
    }

    /**
     * 读取数据后关闭
     * @param tempFilePath
     */
    public void readClose(String tempFilePath) throws IOException {
        dataWorkbook.get(tempFilePath).close();
        dataWorkbook.remove(tempFilePath);
    }

    static class ListKeys{
        private String names;
        private String ages;
        private String sexs;
        private String deses;

        public String getNames() {
            return names;
        }

        public void setNames(String names) {
            this.names = names;
        }

        public String getAges() {
            return ages;
        }

        public void setAges(String ages) {
            this.ages = ages;
        }

        public String getSexs() {
            return sexs;
        }

        public void setSexs(String sexs) {
            this.sexs = sexs;
        }

        public String getDeses() {
            return deses;
        }

        public void setDeses(String deses) {
            this.deses = deses;
        }

        @Override
        public String toString() {
            return "ListKeys{" +
                    "names='" + names + '\'' +
                    ", ages='" + ages + '\'' +
                    ", sexs='" + sexs + '\'' +
                    ", deses='" + deses + '\'' +
                    '}';
        }
    }

    static class ObjectKeys{
        private String name;
        private String age;
        private String sex;
        private String des;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public String getDes() {
            return des;
        }

        public void setDes(String des) {
            this.des = des;
        }
    }
    public static void main(String args[]) throws IOException, InvocationTargetException, IllegalAccessException, InstantiationException, IntrospectionException {
        System.out.print(ExcelHandle.class.getResource(""));
        String tempFilePath = "C:\\Users\\mam\\Desktop\\test.xlsx";
        List<String> dataListCell = new ArrayList<String>();
        dataListCell.add("names");
        dataListCell.add("ages");
        dataListCell.add("sexs");
        dataListCell.add("deses");
        /*List<Map<String,Object>> dataList = new  ArrayList<Map<String,Object>>();
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("names", "names");
        map.put("ages", 22);
        map.put("sexs", "男");
        map.put("deses", "测试");
        dataList.add(map);
        Map<String,Object> map1 = new HashMap<String, Object>();
        map1.put("names", "names1");
        map1.put("ages", 23);
        map1.put("sexs", "男");
        map1.put("deses", "测试1");
        dataList.add(map1);
        Map<String,Object> map2 = new HashMap<String, Object>();
        map2.put("names", "names2");
        map2.put("ages", 24);
        map2.put("sexs", "女");
        map2.put("deses", "测试2");
        dataList.add(map2);
        Map<String,Object> map3 = new HashMap<String, Object>();
        map3.put("names", "names3");
        map3.put("ages", 25);
        map3.put("sexs", "男");
        map3.put("deses", "测试3");
        dataList.add(map3);*/

        List<ListKeys> list = new ArrayList<>();
        ListKeys l1 = new ListKeys();
        l1.setAges("22");l1.setNames("names1");l1.setSexs("男");l1.setDeses("测试");
        list.add(l1);
        ListKeys l2 = new ListKeys();
        l2.setAges("23");l2.setNames("names2");l2.setSexs("男");l2.setDeses("测试2");
        list.add(l2);
        ListKeys l3 = new ListKeys();
        l3.setAges("24");l3.setNames("names3");l3.setSexs("女");l3.setDeses("测试3");
        list.add(l3);
        WriteConfig writeConfig = new WriteConfig();
        //writeConfig.setArrayKeys(dataListCell);
        writeConfig.setArrayContent(list);

        ExcelHandle handle = new  ExcelHandle();
        handle.writeListData(tempFilePath, writeConfig, 0);


        List<String> dataCell = new ArrayList<String>();
        dataCell.add("name");
        dataCell.add("age");
        dataCell.add("sex");
        dataCell.add("des");
        /*Map<String,Object> dataMap = new  HashMap<String, Object>();
        dataMap.put("name", "name");
        dataMap.put("age", 11);
        dataMap.put("sex", "女");
        dataMap.put("des", "测试");*/
        ObjectKeys obj = new ObjectKeys();
        obj.setAge("11");obj.setName("aa");obj.setSex("man");obj.setDes("!##@!");
        //writeConfig.setObjectKeys(dataCell);
        writeConfig.setContent(obj);
        handle.writeData(tempFilePath,writeConfig,0);

        File file = new File("d:/data.xlsx");
        OutputStream os = new FileOutputStream(file);
        //写到输出流并关闭资源
        handle.writeAndClose(tempFilePath, os);

        os.flush();
        os.close();

        System.out.println("读取写入的数据----------------------------------%%%");
        System.out.println("name:"+handle.getValue(tempFilePath, "name", 0, file));
        System.out.println("age:"+handle.getValue(tempFilePath, "age", 0, file));
        System.out.println("sex:"+handle.getValue(tempFilePath, "sex", 0, file));
        System.out.println("des:"+handle.getValue(tempFilePath, "des", 0, file));
        System.out.println("读取写入的列表数据----------------------------------%%%");

        ReadConfig readConfig = new ReadConfig();
        //readConfig.setArrayKeys(dataListCell);
        readConfig.setArrayClazz(ListKeys.class);
        readConfig.setObjectClazz(ObjectKeys.class);
        List<Object> list2 = handle.getListValue(tempFilePath, readConfig, 0, file);

        System.out.println(list2.toString());

        handle.readClose(tempFilePath);
    }

}